<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>flat与flatMap</title>
  </head>
  <body>
    <script>
      // flat 平
      // 将多维数组的维度降低
      const arr = [
        [1, 2],
        [3, 4],
      ]; // 二维数组转一维数组
      console.log(arr.flat()); // [1,2,3,4]

      // 三维数组转二维数组
      const arr2 = [
        [1, 2, [5, 6]],
        [3, 4],
      ];
      console.log(arr2.flat()); //[1, 2, Array(2), 3, 4]
      // 三维数组转一维数组
      // 参数为深度 是一个数字 默认值为1
      console.log(arr2.flat(2)); //[1, 2, 5, 6, 3, 4]

      const arr3 = [1, 2, 3, 4];
      const result = arr3.flatMap((item) => item * 10);
      console.log(result); //[10, 20, 30, 40]
    </script>
  </body>
</html>
